package com.my.lists;

import com.my.lists.bean.User;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: marshal
 * @date: 2022-07-11 14:14
 */
public class Test {
    public static void main(String[] args) {
        var tom = new User();
        var hobbies = new ArrayList<String>();
        tom.setHobbies(hobbies);
        System.out.println(tom);
        // 1. 直接对hobbies进行赋值，tom这个对象的hobbies字段也会跟着变化
        hobbies.addAll(List.of("read", "movie", "swimming"));
        System.out.println(tom);
        // 2. 使用 tom.getHobbies()来修改tom这个对象的hobbies字段
        tom.getHobbies().addAll(List.of("music", "basketball"));
        System.out.println(tom);
    }
}
